
<form action="index.php?app=b2c&ctl=admin_goods_editor&act=toAdd" method="post" name="gEditor" id="gEditor">
  <input type="hidden" name="goods[goods_id]" value="<{$goods.goods_id}>" id="gEditor-GId-input"/>
  <input type="hidden" name="productkey" value="<{$productkey}>"/>
  <div id="gEditor-Body">
     <{include file="admin/goods/detail/page.html"}>
  </div>
</form>
<!-- 暂时先注释掉，优化的时候统一修改 -->
<div class="std-upload-txt" style="display:none;top:429px;top:460px\9;left:280px;">
	<div><{t}>无法打开图片选择窗口？点此<{/t}></div>
	<div class="browse">
		<form target="upload" method="post" enctype="multipart/form-data" action="#">
			<input type="file" name="Filedata" onchange="new StdUpload('index.php?app=image&ctl=admin_manage&act=gimage_swf_remote&sess_id='+sess_id,'add_img').start();" />
		</form>
		&nbsp;&nbsp;<a href="javascript:void(0);" class="btn"><span><span><{t}>上传图片<{/t}></span></span></a>
	</div>
	<div class="std-loading-icon"></div>
</div>
<script>
var goodsEditor = null;

var goodsEditFrame = (function(){
  goodsEditor = new ShopExGoodsEditor('gEditor',{imgtype:'<{$uploader}>',url:'<{$url}>',goods_id:'<{$goods.id}>'});
  Ex_Loader('uploader',function(){
		new Swiff.Uploader( {
			verbose: true,
			url:'index.php?app=image&ctl=admin_manage&act=gimage_swf_remote&sess_id='+sess_id,
			path: '<{$image_dir}>/uploader.swf',
			typeFilter: {
				'Images (*.jpg, *.jpeg, *.gif, *.png)': '*.jpg; *.jpeg; *.gif; *.png'
			},
			fileSizeMax:<{$IMAGE_MAX_SIZE}>,
			target:'pic-uploader',
			onSelect:function(rs){
				if(rs)
				rs.each(function(v){
					if(v.size>this.fileSizeMax){
						alert(v.name+'<{t}>\n\n文件超出大小<{/t}>');
					};
				},this);
			},
			onSelectFail:function(rs){
				rs.each(function(v){
					if(v.validationError=='sizeLimitMax'){
						alert(v.name+'<{t}>\n\n文件超出大小<{/t}>');
					};
				});
			},
			onSelectSuccess:function(rs){
				var PID='up_';
				var _this=this;
				rs.each(function(v,i){
					 new Element('div',{'class':'gpic-box','id':PID+v.id}).inject($('all-pics'));
				});
				this.start();
			},
			onFileOpen:function(e){
				$('up_'+e.id).setHTML('<em style="font-size:13px;font-family:Georgia;">0%</em>');
			},
			onFileProgress:function(e){
				$('up_'+e.id).getElement('em').set('text',e.progress.percentLoaded+'%');
			},
			onFileComplete: function(res){
				if(res.response.error){
					return  new MessageBox('<{t}>文件<{/t}>'+res.name+'<{t}>上传失败<{/t}>',{type:'error',autohide:true});
				}
				$('up_'+res.id).setHTML(res.response.text);
				if(!$E('#pic-area .current')&&$E('#pic-area .gpic')){
				  $E('#pic-area .gpic').onclick();
				}
			}
		});

	});
	    /*
         *  sign:{
               1:保存并增加相似商品,
               2:保存并返回,
               3:保存当前不返回，
         *    }
         */
   var _form=$('gEditor'),_formActionURL=_form.get('action');


   subGoodsForm = function (event,sign){
	   var specOBJ='';
	   var _target=$(new Event(event).target);

	   if($('productNode')&&$('productNode').retrieve('specOBJ')){
			if(!$('productNode').retrieve('specOBJ').data.length){
				return new MessageBox('<{t}>请先添加货品!!!<{/t}>',{type:'error',autohide:true});
			}
			specOBJ=$('productNode').retrieve('specOBJ').toHideInput($('productNode').getElement('tr'));
	   }
	   var target={extraData:$('finder-tag').toQueryString()+'&'+specOBJ,onRequest:function(){_target.disabled = true;}};

	   switch (sign){
			case 1:                    //添加相似
				$extend(target,{
					onComplete:function(){
						if(window.opener.finderGroup&&window.opener.finderGroup['<{$env.get.finder_id}>'])
						window.opener.finderGroup['<{$env.get.finder_id}>'].refresh();
						clearOldValue();
						_target.disabled = false;
				}});
			break;
			case 2:                   //保存关闭
				$extend(target,{
					onComplete:function(rs){
						if(rs&&!!JSON.decode(rs).success){
							if(window.opener.finderGroup&&window.opener.finderGroup['<{$env.get.finder_id}>']){
								window.opener.finderGroup['<{$env.get.finder_id}>'].refresh();
							}
							window.close();
						}
                        _target.disabled = false;
					}}
				);
			break;
			case 3:
				$extend(target,{            //保存当前
					onComplete:function(rs){
						var id = JSON.decode(rs).goods_id;
						if(id > 0){
							$('gEditor-GId-input').value =id;
						}
						if(window.opener.finderGroup&&window.opener.finderGroup['<{$env.get.finder_id}>'])
						window.opener.finderGroup['<{$env.get.finder_id}>'].refresh();

						_target.disabled = false;
					}}
				);
			break;
	   }

		_form.store('target',target);
        _form.set('action',_formActionURL+'&but='+sign).fireEvent('submit',new Event(event));
    };

	var clearOldValue=function(){
		 $('id_gname').set('value','');
		 $('gEditor-GId-input').set('value','');
		 if($$('.product_id').length)
		 $$('.product_id').each(function(el){
			el.value='';
		 });
	}
});

goodsEditFrame();
</script>
<script>
(function(){
   /* var cur = '<{$workground.menu_title}>';
	$$('.head-nav .wg').each(function(wg){

		if(cur&&wg.getElement('span:contains("<{$workground.menu_title}>")')){
			wg.addClass('current');
		}else{
			wg.removeClass('current');
		}

	});  */

	$$('.side-bx-title').addEvent('click', function(e){
		e.stop();
		var bx = this.getParent(),
			bd = this.getNext('.side-bx-bd');
		if(bx.hasClass('side-bx-toggled')){
			bd.show();
			bx.removeClass('side-bx-toggled');
		}else{
			bd.hide();
			bx.addClass('side-bx-toggled');
		}
	});
})();
</script>
